package cn.com.czpb.client.net;

import cn.com.czpb.client.api.BaseHttpService;
import cn.com.czpb.client.api.InterfaceJsonfile;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 猪猪侠 on 2017/6/30.
 */

public class Factory {
    public static BaseHttpService provideHttpService() {
        return providesService(BaseHttpService.class);
    }
    private static Map<Class, Object> sMService = new HashMap();
    private static Map<Class, Object> sMService2 = new HashMap();
    private static Map<Class, Object> sMService3 = new HashMap();
    private static <T> T providesService(Class cls){
        Object service = sMService.get(cls);
        if (service==null){
            synchronized (cls){
                service = sMService.get(cls);
                if (service==null){
                    service=HttpClient.getIns(InterfaceJsonfile.PATH_ROOT).createService(cls);
                    sMService.put(cls,service);
                }
            }
        }
        return (T) service;
    }
    public static BaseHttpService provideHttpService2() {
        return providesService2(BaseHttpService.class);
    }



    private static <T> T providesService2(Class cls){
        Object service = sMService2.get(cls);
        if (service==null){
            synchronized (cls){
                service = sMService2.get(cls);
                if (service==null){
                    service=HttpClient2.getIns(InterfaceJsonfile.WEATHER_ROOT).createService(cls);
                    sMService2.put(cls,service);
                }

            }
        }
        return (T) service;
    }
    public static BaseHttpService provideHttpService3() {
        return providesService3(BaseHttpService.class);
    }
    private static <T> T providesService3(Class cls){
        Object service = sMService3.get(cls);
        if (service==null){
            synchronized (cls){
                service = sMService3.get(cls);
                if (service==null){
                    service=HttpClient3.getIns(InterfaceJsonfile.CITY_ROOT).createService(cls);
                    sMService3.put(cls,service);
                }

            }
        }
        return (T) service;
    }
}
